<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<script type="text/javascript" src="js/jquery-1.9.1.js"></script>
<script type="text/javascript">
	$(document).ready(function(){
		$("#searchZipBtn").click(function(){
			var dong=$("#dong").val();
			$.ajax({
				type:"POST",
				url:"findAddressByZipcode.do",
				data:"dong="+dong,
				dataType:"json",
				success:function(data){
					var str="";
					$.each(data,function(index,data){
						//번지값이 null인 주소값 처리
						if(data.bunji==null){
							str+="<a href=''><font size=2 color='#FF7012'>"+data.zipcode
							+" "+data.sido+" "+data.gugun+" "+data.dong+"</font></a><br>";
						}else{
							str+="<a href=''><font size=2 color='#FF7012'>"+data.zipcode
							+" "+data.sido+" "+data.gugun+" "+data.dong+" "+data.bunji+"</font></a><br>";
						}
						$("#addressZipList").html(str);
					});//each
				}//success
			});//ajax
		});//click
		$("#addressZipList").on("click","a",function(event){
			event.preventDefault();
			var result=$(this).text();
			var zip=result.substr(0,7);
			var address=result.substr(8);
			//opener.document.getElementById(codeaddress).value=$(this).text();
			//jQuery로 opener를 구현해봄...
			$("#zipcode",opener.document).val(zip);
			$("#codeaddress",opener.document).val(address);
			window.close();
		});
	});//ready
</script>

<h2>주소검색</h2>
<table bgcolor="#EAEAEA">
<tr>
<td>
<font size="2" color="grey" style="font-family: '나눔고딕'">
동/읍/면/리 이름을 입력하세요. 예) 역삼동, 화도읍, 장유면
</font>
<form action="findAddressByZipcode.do" method="post" id="findAddressByZipcodeForm">
<input type="text" name="dong" id="dong" onkeydown="javascript:if(event.keyCode==13){return false;}">
<input type="button" name="searchZipBtn" id="searchZipBtn" value="주소검색">
</form>
</td>
</tr>
</table>
<div id="addressZipList"></div>